package top.chmin.project.cloud.common.aop;

import cn.hutool.json.JSONUtil;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;
import top.chmin.project.cloud.common.entity.Page;
import top.chmin.project.cloud.common.tool.LocalTool;

/**
 * chmin
 * 2023/12/21 14:15
 * cloud-builder
 */
@Slf4j
@Aspect
@Component
public class ControllerAop {
    @Pointcut("execution(* top.chmin.project.cloud..*Controller.*(..))")
    public void initLocalPointcut() {

    }

    @Before("initLocalPointcut()")
    public void initLocal(JoinPoint point) {
        log.info("切入方法：{}.{}", point.getTarget().getClass().getName(), point.getSignature().getName());
        Object[] args = point.getArgs();
        log.info("传入参数：{}", JSONUtil.toJsonStr(args));
        for (Object arg : args) {
            if (arg instanceof Page<?> page) {
                LocalTool.setPage(page);
            }
        }
    }
}
